package
{
	import UIFree.abox.uif_moduleBox;
	import UIFree.graphicTools.angle.uif_directCtrl;
	import UIFree.graphicTools.angle.uif_radialLimb;
	import UIFree.graphicTools.color.uif_gradientPalette;
	import UIFree.graphicTools.color.uif_previewColorSpot;
	import UIFree.graphicTools.color.uif_rgbPalette;
	import UIFree.graphicTools.color.uif_spectrumPalette;
	import UIFree.uif_app;
	import UIFree.uif_ecomponent;
	import UIFree.uif_styles;
	
	import UIUtils.uif_color;
	import UIUtils.uif_util;
	import UIUtils.uif_utilBitmap;
	
	import classes.c_styles;
	
	import components.brush.c_baseBrush;
	import components.brush.c_colorSelectEraser;
	import components.brush.c_spotBrush;
	import components.c_moduleBoxWindow;
	import components.dialogs.adjustments.c_Text;
	import components.dialogs.brush.c_brushParams;
	import components.dialogs.brush.c_spotBrushParams;
	import components.dialogs.c_propertyDialog;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BlendMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	[SWF(width="760", height="760", backgroundColor="#FFFFFF")]
	public class collagesPDialog extends uif_app {
		private var brush		: c_colorSelectEraser;
		private var _brushSpot	: Bitmap;
		private var dist		: Bitmap; 
		private var _prevPoint	: Point;
		
		public function collagesPDialog() {
			super(new c_styles());
			styleClass = 'blue';
			resize(stage.stageWidth, stage.stageHeight);
//			uif_utilBitmap.loadAsBitmap('http://content.foto.mail.ru/mail/fwadim/_cover/i-2405.jpg', asPropertyDialog);
			
			var rect: Rectangle = getInner();
			var expData: Object = {
				groups: [
					{
						id: 1,
						name: 'Женские'	
					},
					{
						id: 2,
						name: 'Мужские'	
					}
				],
				list: [
					{
						id: 1,
						group: 1
					},{
						id: 2,
						group: 1
					},{
						id: 3,
						group: 2
					},{
						id: 4,
						group: 2
					},{
						id: 5,
						group: 1
					}
				]
			};
			
			var dlg: c_moduleBoxWindow = new c_moduleBoxWindow(this, expData, 'http://188.127.227.87/games/data/clothing/cloth/jpg_preview/i', 'SELECTOBJ', 
				2, 600, 180, 'data module');
			
			dlg.show();
		}
		
		protected function asPropertyDialog(a_dist: Bitmap): void {
			var a_image: uif_ecomponent = new uif_ecomponent(this, 0, 0, a_dist.width, a_dist.height);
			dist = a_dist;
			dist.blendMode = BlendMode.LAYER;
			dist.alpha = 1;
			a_image.addChild(dist);
			
			brush = new c_colorSelectEraser();
			brush.colorTransform = new ColorTransform(1, 1, 1, 0.5);
			brush.blendMode = BlendMode.NORMAL;
			brush.stamp 	= c_baseBrush.createSpotStamp(20, 0);
			brush.blur 		= 5;
			brush.stepLen 	= 20;
			
			a_image.addEventListener(MouseEvent.MOUSE_MOVE, doMove);
			a_image.addEventListener(MouseEvent.MOUSE_DOWN, doMouseDown);
			a_image.addEventListener(MouseEvent.MOUSE_UP, doMouseUp);
			
			var pd: c_spotBrushParams = new c_spotBrushParams(this, brush, 'Параметры'); 
			pd.alignApply('right');
			pd.show();
			
			//			new uif_directCtrl(this, 10, 10, 80, 'directControl');
			//new uif_rgbPalette(this, 10, 10, 300, 200, 'paletteCtrl');
			//			new uif_spectrumPalette(this, 10, 10, 300, 50, 'paletteCtrl');
			//new uif_gradientPalette(this, 10, 10, 300, 300, 'paletteCtrl');
			
			pd.addEvent(Event.CHANGE, function(e: Event): void {
				updateBrushSpot();
				sysTrace(pd.values[0].value);
			});
			
			_brushSpot = new Bitmap();
			_brushSpot.blendMode = BlendMode.DIFFERENCE;
			addChild(_brushSpot);
			updateBrushSpot();
			
			(new c_propertyDialog(this, [{
				title	: 'Цветовой баланс',
				type	: c_propertyDialog.PTYPE_CHECKBOXLIST,
				value	: 2,
				values	: [
					{
						caption: 'item1',
						checked: true
					},{
						caption: 'item2',
						checked: false
					},{
						caption: 'item3',
						checked: true
					},{
						caption: 'item4',
						checked: false
					},{
						caption: 'item5',
						checked: true
					},{
						caption: 'item6',
						checked: false
					},{
						caption: 'item7',
						checked: false
					},{
						caption: 'item8',
						checked: false
					}
				]
			}], 'exp')).addEvent(Event.CHANGE, function(e: Event): void {
				trace(e);
			});			
		}
		
		protected function updateBrushSpot(): void {
			if (_brushSpot.bitmapData) _brushSpot.bitmapData.dispose();
			_brushSpot.bitmapData = brush.createStampImage();
		}
		
		protected function doMove(e: MouseEvent): void {
			if (e.buttonDown) brush.sessionPaintTo(mousePos);
			_brushSpot.x = mouseX + brush.bounds.x;
			_brushSpot.y = mouseY + brush.bounds.y;
		}
		
		protected function doMouseDown(e: MouseEvent): void {
			brush.beginSession(dist.bitmapData, mousePos);
		}
		
		protected function doMouseUp(e: MouseEvent): void {
			brush.endSession();
		}
	}
}